package com.stylefeng.guns.modular.capitalBudget;

import com.stylefeng.guns.modular.system.model.CapitalBudget;
import com.stylefeng.guns.modular.system.model.Payroll;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 将excel表的数据转换成资金预算表对应的实力类数据
 * @author laoyu
 * @date 2018-07-24
 */
public  class MapToCapitalBudget {


    /**
     * 将excel表的数据转换成资金预算表对应的实力类数据
     * @param list
     * @param payTime
     * @param platform
     * @return
     * @author laoyu
     * @date 2018-07-24
     * @throws Exception
     */
    public static   List<CapitalBudget> mapToCapitalBudget(List<Map<String,Object>> list, String payTime,String platform)throws Exception{
        Date nowDate = new Date();
        List<CapitalBudget> payrollList = new ArrayList<>();
        for (int i = 0; i < list.size()-2; i++) {//excel表解析时会多解析两条空数据
            CapitalBudget capitalBudget = new CapitalBudget();
            Map<String, Object> map = list.get(i);
            if ("一".equals(map.get("number"))){//表格中对应的序号
                capitalBudget.setNumber(1);
            }
            else if ("二".equals(map.get("number"))){
                capitalBudget.setNumber(2);
            }
            else if ("三".equals(map.get("number"))){
                capitalBudget.setNumber(3);
            }
            capitalBudget.setProject(map.get("project").toString());
            if(map.get("incomePS")!=null)
                capitalBudget.setIncomePS(Double.parseDouble(map.get("incomePS").toString()));
            if(map.get("incomeRMB")!=null)
                capitalBudget.setIncomeRMB(Double.parseDouble(map.get("incomeRMB").toString()));
            if(map.get("expenditurePS")!=null)
                capitalBudget.setExpenditurePS(Double.parseDouble(map.get("expenditurePS").toString()));
            if(map.get("expenditureRMB")!=null)
                capitalBudget.setExpenditureRMB(Double.parseDouble(map.get("expenditureRMB").toString()));
            if(map.get("remarks")!=null)
                capitalBudget.setRemarks(map.get("remarks").toString());

            capitalBudget.setRevDate(payTime);
            capitalBudget.setCreattime(nowDate);
            capitalBudget.setUpdatetime(nowDate);
            capitalBudget.setPlatform(platform);

           payrollList.add(capitalBudget);
        }
        return payrollList;
    }

}
